package com.sh.data.engine.domain.shims;

import com.sh.data.engine.domain.base.model.enums.Database;
import com.sh.data.engine.domain.shims.db.BaseDbManager;
import com.sh.data.engine.domain.shims.db.DbOptions;
import com.sh.data.engine.domain.shims.db2.manager.Db2Manager;
import com.sh.data.engine.domain.shims.dm8.manager.Dm8Manager;
import com.sh.data.engine.domain.shims.hbase.manager.HBaseManager;
import com.sh.data.engine.domain.shims.hive.manager.HiveManager;
import com.sh.data.engine.domain.shims.influxdb.manager.InfluxDBManager;
import com.sh.data.engine.domain.shims.influxdb.option.InfluxDbOptions;
import com.sh.data.engine.domain.shims.kingbase8.manager.Kingbase8Manager;
import com.sh.data.engine.domain.shims.mongo.MongoOptions;
import com.sh.data.engine.domain.shims.mongo.manager.MongoManager;
import com.sh.data.engine.domain.shims.mysql.manager.MysqlManager;
import com.sh.data.engine.domain.shims.oracle.manager.OracleManager;
import com.sh.data.engine.domain.shims.postgresql.manager.PostgreSqlManager;
import com.sh.data.engine.domain.shims.saphana.manager.SapManager;
import com.sh.data.engine.domain.shims.sqlserver.manager.SqlServerManager;
import com.sh.data.engine.domain.shims.tidb.manager.TidbManager;
import lombok.extern.slf4j.Slf4j;

/**
 * @author: mengzheng.mhc
 * @date: 2024/6/5 14:15
 */
@Slf4j
public class DbManagerFactory {

    public static BaseDbManager getDbManager(Database database, DbOptions dbOptions) {

        if (dbOptions != null && dbOptions.getDatabase() == null) {
            dbOptions.setDatabase(database);
        }

        return switch (database) {
            case MYSQL -> new MysqlManager(dbOptions);
            case ORACLE -> new OracleManager(dbOptions);
            case DB2 -> new Db2Manager(dbOptions);
            case SAP -> new SapManager(dbOptions);
            case SQLSERVER -> new SqlServerManager(dbOptions);
            case POSTGRESQL -> new PostgreSqlManager(dbOptions);
            case HIVE -> new HiveManager(dbOptions);
            case DM -> new Dm8Manager(dbOptions);
            case KINGBASE8 -> new Kingbase8Manager(dbOptions);
            case TIDB -> new TidbManager(dbOptions);
            default -> null;
        };
    }

    public static MongoManager getMongoManager(MongoOptions options) {
        return new MongoManager(options);
    }

    public static HBaseManager getHBaseManager(String configJson) {
        return new HBaseManager(configJson);
    }

    public static InfluxDBManager getInfluxDbManager(InfluxDbOptions options) {
        return new InfluxDBManager(options);
    }

    public static void main(String[] args) {
        final BaseDbManager dbManager = DbManagerFactory.getDbManager(Database.ORACLE, null);

        final String s = dbManager.toPostgresqlType(1);

        System.out.println(s);
    }
}
